﻿package {
	import laya.display.Sprite;
	import laya.ui.Label;
	import laya.utils.Dictionary;
	import ui.testpageUI;
	public class LayaSample {
		
		private var actSnows:Array;
		private var showSnows:Array;
		private var isLock:Boolean;

		public function LayaSample() {
			//初始化引擎			
			Laya.init(680, 480);
			Laya.stage.bgColor="#999999";			
			trace("Hello","哈哈");
			Laya.stage.addChild(new testpageUI());
			return;


			actSnows = [];
			showSnows = [];
			
			var sp:Sprite = new Sprite();
			sp.graphics.drawRect(0,0,100,100,"#ff0000");			
			Laya.stage.addChild(sp);
			sp.pos(50,50);
			
			var lbl:Label = new Label();
			Laya.stage.addChild(lbl);
			lbl.size(120,30);
			lbl.text="Hello lbl";
			Laya.timer.loop(60,this,onCreateSnows,null,true);
			Laya.timer.loop(50,this,onSnowDown,null,true);
			
			
			
		}
		private function onSnowDown():void
		{
			for each(var sp:Sprite in showSnows)
			{				
				sp.y+=10;
				if(sp.y>=Laya.stage.height)
				{
					isLock = true;
					var i:int = showSnows.indexOf(sp);
					showSnows.splice(i,1);
					if(sp.parent)
					{
						sp.parent.removeChild(sp);
					}
					actSnows.push(sp);
				}else if(isLock)
				{
					isLock = false;
				}
			}
					
		}
		private var count:int;
		private function onCreateSnows():void
		{
			if(!isLock)
			{
				var sp:Sprite = createSnow();
				var spaceX:Number = 25;
				var px:Number = spaceX+Math.random()*(Laya.stage.width-spaceX);
				var py:Number = 10+Math.random()*50;
				sp.pos(px,py);
				showSnows.push(sp);
				Laya.stage.addChild(sp);
			}						
		}
		private function createSnow():Sprite
		{
			var sp:Sprite
			if(actSnows.length>0)
			{				
				sp = actSnows.shift();
			}else
			{
				sp = new Sprite();
				sp.graphics.drawCircle(0,0,5,'#ffffff');
				count++;				
			}						
			return sp;
		}


	}

}